package com.senlingspace.web.controller.douyin;

import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.payment.core.ConcreteOrderProcess;
import com.senlingspace.payment.douyin.DouyinHttpClient;
import com.senlingspace.payment.douyin.bean.request.DouyinOrderRequest;
import com.senlingspace.payment.douyin.bean.response.DouyinOrderResponse;
import com.senlingspace.payment.douyin.service.DouYinOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;


/**
 * 抖音订单控制器
 */
@Slf4j
@Validated
@AllArgsConstructor
@RestController
@RequestMapping(path = "/douyin/order/v1")
public class DouYinOrderController {

    private final ConcreteOrderProcess concreteOrderProcess;
    DouYinOrderService douYinOrderService;
    /**
     * 抖音订单查询
     */
    @GetMapping(path = "/query")
    public AjaxResult queryOrder(DouyinOrderRequest douyinOrderRequest) {
        DouyinOrderResponse invoke = DouyinHttpClient.invoke(douyinOrderRequest);
        return AjaxResult.success(invoke);
    }


    /**
     * 创建订单（票类订单）
     *
     * @param douyinOrderRequest 订单请求
     * @return {@link AjaxResult }
     */
    @PostMapping(path = "/create")
    public AjaxResult createOrder( DouyinOrderRequest douyinOrderRequest) {

        ArrayList<AjaxResult> ajaxResults  = douYinOrderService.createOrder(douyinOrderRequest);
        return AjaxResult.success(ajaxResults);
    }
}
